#include <fermat/parser/attributes.h>
#include <fermat/parser/attributes_parser.h>
#include <gtest/gtest.h>
#include <string>
using std::string;
using namespace fermat::parser;
TEST(parser, attr_empty)
{
	Attributes attrs;
	std::istringstream istr("");
	AttributesParser parser(attrs, istr);
	parser.parse();
    EXPECT_EQ(attrs.begin(), attrs.end()); 
}

TEST(parser, attr_kv1)
{
	Attributes attrs;
	std::istringstream istr("name=value");
	AttributesParser parser(attrs, istr);
	parser.parse();
    EXPECT_EQ(attrs.getString("name"), "value"); 
}

TEST(parser, attr_kv2)
{
	Attributes attrs;
	std::istringstream istr("name=value, name2=100");
	AttributesParser parser(attrs, istr);
	parser.parse();
    EXPECT_EQ(attrs.getString("name"), "value"); 
    EXPECT_EQ(attrs.getInt("name2"), 100); 
}

TEST(parser, attr_kv3)
{
	Attributes attrs;
	std::istringstream istr("name=value, name2=100, name3");
	AttributesParser parser(attrs, istr);
	parser.parse();
    EXPECT_EQ(attrs.getString("name"), "value"); 
    EXPECT_EQ(attrs.getInt("name2"), 100); 
    EXPECT_EQ(attrs.getBool("name3"), true); 
}

TEST(parser, attr_kv4)
{
	Attributes attrs;
	std::istringstream istr("name.a=value, name.b=100, name.c");
	AttributesParser parser(attrs, istr);
	parser.parse();
    EXPECT_EQ(attrs.getString("name.a"), "value"); 
    EXPECT_EQ(attrs.getInt("name.b"), 100); 
    EXPECT_EQ(attrs.getBool("name.c"), true); 
}

TEST(parser, attr_kv5)
{
	Attributes attrs;
	std::istringstream istr("name = {a=value, b=100, c}");
	AttributesParser parser(attrs, istr);
	parser.parse();
    EXPECT_EQ(attrs.getString("name.a"), "value"); 
    EXPECT_EQ(attrs.getInt("name.b"), 100); 
    EXPECT_EQ(attrs.getBool("name.c"), true); 
}

TEST(parser, attr_kv6)
{
	Attributes attrs;
	std::istringstream istr("name = {a=value, b=100, c}, name2=\"foo\"");
	AttributesParser parser(attrs, istr);
	parser.parse();
    EXPECT_EQ(attrs.getString("name.a"), "value"); 
    EXPECT_EQ(attrs.getInt("name.b"), 100); 
    EXPECT_EQ(attrs.getBool("name.c"), true); 
    EXPECT_EQ(attrs.getString("name2"), "foo"); 
}
